package hongcaosp.app.android.video.player;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class RGPhoneStateListener extends PhoneStateListener implements Application.ActivityLifecycleCallbacks {

    int activityCount;

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);

        switch (state) {
            //电话等待接听
            case TelephonyManager.CALL_STATE_RINGING:
                break;
            //电话接听
            case TelephonyManager.CALL_STATE_OFFHOOK:
                break;
            //电话挂机
            case TelephonyManager.CALL_STATE_IDLE:
                if (isInBackground())
                break;
        }
    }

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {
        activityCount++;
    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {
        activityCount--;
    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }

    public boolean isInBackground() {
        return (activityCount < 0);
    }
}
